<template>
  <div class="container">
    <div class="main">
      <div class="leftside">
        <Leftside></Leftside>
      </div>
      <div class="center">
        <div class="heade">分类 {{ route.params.name }} 下的文章</div>
        <Listitem :data="categorydata || []" />
        <el-pagination
          background
          layout="prev, pager, next"
          @current-change="hanldlecurrent"
          :page-size="pagination.size"
          v-model="pagination.currentpage"
          :total="pagination.count">
        </el-pagination>
      </div>
      <div class="rightside">
        <RightsideVue :data="articledata"></RightsideVue>
      </div>
    </div>
  </div>
</template>

<script setup>
import Leftside from '@/components/Leftside.vue'
import Listitem from '@/components/Listitem.vue'
import {searchdata, sarticlebytype} from "../../apis/article";
import RightsideVue from '@/components/Rightside.vue'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router';
const route = useRoute()
onMounted(()=>{
  getarticledata()
  getcategorydata()
})
const pagination = ref({
  currentpage: 1,
  size: 10,
  count: 10
})
const articledata = ref([])
const getarticledata = () =>{
  let params = {
    page: pagination.value.currentpage,
    size: pagination.value.size
  }
  searchdata(params).then((res)=>{
    articledata.value = res.data.data
    pagination.value.count = res.data.count
    console.log(articledata.value, 'data')
  })
}
const hanldlecurrent = (currentpage) =>{
  pagination.value.currentpage = currentpage
  console.log(currentpage, 'currentpage')
  getcategorydata()
}
const categorydata = ref([])
const getcategorydata = () =>{
  let params = {
    type: route.params.name,
    page: pagination.value.currentpage,
    size: pagination.value.size
  }
  sarticlebytype(params).then((res)=>{
    if (res.data.isok) {
      categorydata.value = res.data.data
      console.log(categorydata.value, 'data')
      pagination.value.count = res.data.count
    }
  })
}
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  min-height: 100vh;
  margin-top: 60px;
  background-color: #f5f5ff;
  .heade{
    height: 50px;
    line-height: 50px;
    background-color: #fff;
    color: #000;
    text-align: center;
    font-size: 24px;
    padding: 10px;
    box-shadow: #303133 0px 0px 5px;;
    margin: 10px 0;
  }
}
.header {
  padding-bottom: 10px;
  .img{
    width: 100%;
    object-fit: cover;
  }
}
.main {
  display: flex;
  justify-content: center;
  .center {
    padding: 0 20px;
    .body{
      padding: 20px;
    }
    .image{
      max-width: 100%;
      border-radius: 10px;
    }
  }
}
.time{
  margin-top: 10px;
}
</style>
